export default function (e, notification) {
	const errObj = {
		site_login: {
			form: {
				login_form_action_url: ' 请输入form登录url',
				login_form_postdata: '请输入form登录post',
			},
			json: {
				login_json_action_url: '请输入json登录url',
				login_json_postdata: '请正确输入json登录post',
			},
			cookie: { request_cookie: '请正确输入登录cookie' },
			headers: { request_http_headers: '请正确输入登录headers' },
		},
		is_http_auth_enabled: {
			http_auth_username: '请输入http用户名',
			http_auth_password: '请输入http登录密码',
		},
		is_proxy_enabled: {
			proxy_scheme: '请输入代理类型',
			proxy_host: '请输正确输入代理ip',
			proxy_port: '请输正确输入代理端口',
		},
	};
	let message = '';
	if (!e.prelogin) {
		return true;
	}
	if (e.prelogin.site_login) {
		Object.keys(errObj.site_login[e.prelogin.login_method]).forEach(key => {
			const value = e.prelogin[key];
			const errMsg = errObj.site_login[e.prelogin.login_method][key];
			if (!value && key === 'login_json_action_url') {
				message = errMsg;
			} else if (key === 'login_json_postdata') {
				try {
					JSON.parse(value);
				} catch (error) {
					message = errMsg;
				}
			} else if (key === 'request_cookie') {
				if (!value.includes('=')) {
					message = errMsg;
				}
			} else if (key === 'request_http_headers') {
				if (!value.includes(': ')) {
					message = errMsg;
				}
			}
		});
	}
	if (e.prelogin.is_http_auth_enabled) {
		Object.keys(errObj.is_http_auth_enabled).forEach(key => {
			if (!e.prelogin[key]) {
				message = errObj.is_http_auth_enabled[key];
			}
		});
	}
	if (e.prelogin.is_proxy_enabled) {
		Object.keys(errObj.is_proxy_enabled).forEach(key => {
			const val = e.prelogin[key];
			if (key === 'proxy_port' && val % 1 !== 0) {
				message = errObj.is_proxy_enabled[key];
			} else if (key === 'proxy_host' && !val) {
				message = errObj.is_proxy_enabled[key];
				// try {
				// 	const url = new URL(`http//${val}`);
				// 	if (!url) throw new Error();
				// } catch (error) {
				// 	message = errObj.is_proxy_enabled[key];
				// }
			}
		});
	}
	console.log(message);
	if (message) {
		notification.error({
			message,
			placement: 'top',
			style: { width: '25rem' },
		});
		return false;
	} else {
		return true;
	}
}
